<template>
	<view class="main-container">
		<picker @change="bindPickerChange" :value="index" :range="items" >
			<view class="picker">
				<text style="margin-left: 4%;">{{items[index]}} ▼</text>
				<text style="margin-right: 8%;">绩点:{{jidian}}</text>
			</view>
		</picker>
		<view class='chengji'>
			<view class='cheng' v-for="(item,index) in chengji" :key="index">
				<view class='left'>
					<text class='name'>{{item.kcmc}}\n</text>
					<text class='detail'>学年学期:{{item.xqmc}}\n课程属性:{{item.kclbmc}}\n考试性质:{{item.ksxzmc}}\n课程性质:{{item.kcxzmc}}</text>
				</view>
				<view class='right'>
					<text class='score'>{{item.zcj}}\n</text>
					<text class='credit'>学分:{{item.xf}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import utils from "../../static/js/utils.js";
	let items = [
		'2019-2020-2',
		'2019-2020-1',
		'2018-2019-2',
		'2018-2019-1',
		'2017-2018-2',
		'2017-2018-1',
		'2016-2017-2',
		'2016-2017-1',
		'2015-2016-2',
		'2015-2016-1',
	];
	export default {
		data() {
			return {
				chengji: [],
				jidian: '0',
				items: [],
				index: 3
			}
		},
		methods: {
			bindPickerChange(event) {
				let {
					value
				} = event.detail;
				this.index = value;
				this.getChengji(this.items[value]);
			},
			pingjunjidian(chengji) {
				let xf = 0;
				let jd = 0;
				chengji.forEach(item => {
					xf += item.xf;
					if (item.zcj == '优') {
						jd += 4.5 * item.xf;
					} else if (item.zcj == '良') {
						jd += 3.5 * item.xf;
					} else if (item.zcj == '中') {
						jd += 2.5 * item.xf;
					} else if (item.zcj == '及格') {
						jd += 1.5 * item.xf;
					} else if (item.zcj >= 60) {
						jd += ((item.zcj - 50) / 10) * item.xf;
					}
				});
				this.jidian = xf == 0 ? 0 : (jd / xf).toFixed(2);
			},
			getChengji(item) {
				utils.loading("加载中");
				let that = this;
				utils.get("news/getgrade", {
					xq: item
				}, function(data) {
					that.chengji = data;
					that.pingjunjidian(data);
				});
			}
		},
		onLoad() {
			this.items = items;
			this.getChengji(items[3]);
		}
	}
</script>

<style>
	.main-container {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	picker {
		width: 100%;
		position: fixed;
		top: 0upx;
		z-index: 999;
		background-color: #ffffff;
		box-shadow: inset 0px -1px 1px -1px #c8c7cc;
	}

	.picker {
		width: 100%;
		height: 60upx;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		font-size: 32upx;
		justify-content: space-between;
	}

	.picker .title {
		width: 30%;
		height: 60upx;
		line-height: 60upx;
		text-align: center;
		font-size: 30upx;
		border-right: 1px solid #dcdcdc;
		border-top-left-radius: 3px;
		border-bottom-left-radius: 3px;
	}

	.picker .content {
		width: 50%;
		height: 60upx;
		line-height: 80upx;
		text-align: center;
		font-size: 34upx;
		border-top-right-radius: 3px;
		border-bottom-right-radius: 3px;
	}

	.chengji {
		width: 100%;
		flex-direction: column;
		margin-top: 80upx;
		align-items: center;
		justify-content: center;
		background-color: white;
	}

	.chengji .cheng {
		width: 100%;
		height: 270upx;
		display: flex;
		border-bottom: 2upx solid #f2f2f2;
	}

	.chengji .cheng .left {
		width: 76%;
		margin-left: 4%;
	}

	.chengji .cheng .left .detail {
		font-size: 25upx;
		color: #666;
	}

	.chengji .cheng .left .name {
		font-size: 34upx;
	}

	.chengji .cheng .right {
		width: 20%;
	}

	.chengji .cheng .right .score {
		color: #7bc2e9;
		font-size: 50upx;
	}

	.chengji .cheng .right .credit {
		font-size: 25upx;
		color: #666;
	}

	.chengji .wcj {
		text-align: center;
		color: red;
		height: 80upx;
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		border-bottom: 1px solid #dcdcdc
	}

	.chengji .wcj .content {
		width: 49%;
		height: 80upx;
		display: flex;
		flex-wrap: wrap;
	}

	.chengji .wcj .content view {
		width: 49%;
		text-align: center;
		height: 80upx;
		line-height: 80upx;
		font-size: 30upx;
	}
</style>
